#include <cstdio>

int main( )
{
    int n, i, ans, j;
    long long l, a, b, mod, minn, maxn, x;
    while ( scanf("%d%I64d%I64d%I64d%I64d", &n, &l, &a, &b, &mod) != EOF )
    {
        ans = 0;
        maxn = 0;
        minn = 2000000000;
        for ( i = 1; i <= n; i++ )
        {
            x = ( a * i + b ) % mod;
            if ( x <= l / 2 )
            {
                if ( maxn < x )
                    maxn = x;
                ans++;
            }
            else
                if ( minn > x )
                    minn = x;
        }
        if ( maxn + minn <= l )
            ans++;
        printf("%d\n", ans);
    }
    return 0;
}
